<?php
namespace Mob \ Controller;

use Think \ Controller;
use Think \ Hook;

class ChooseController extends BaseController {

    //发布推荐
     public function newRelease()
     {
     if(IS_POST)
     {
     $uid = get_uid();
     $title = I('post.title',null,'string');
     $attach_ids = I('post.attach_ids',null,'string');
     $contents = I('post.contents',null,'string');
     $urllink = I('post.urllink',null,false);
     $schooId = I('post.schooId',10183,'int');
     $serialno = D('Choose')->creator($title,$contents,$urllink,$attach_ids,$uid,$schooId);
     if($serialno)
     {
     $this->redirect('Choose/chooseDetails',array('serialno'=>$serialno));
     }

     }else
     {
     $this->display();

     }
     }
     public function showDaysChoose()
     {
     $uid = get_uid();
     $chooseDetails = D('Choose')->get_todayChoose();
     if($chooseDetails['is_img']==1)
     {          //获得原图
                $bi = M('Picture')->where(array('status' => 1))->getById($chooseDetails['attach_ids']);
                if (!is_bool(strpos($bi['path'], 'http://'))) {
                    $chooseDetails['sourceId_img_big'] = $bi['path'];
                } else {
                    $chooseDetails['sourceId_img_big'] = getRootUrl() . substr($bi['path'], 1);
                }
     }
     $urlLick = $chooseDetails['urllink'];
     if($urlLick!=null)
     {
      if(!stristr($urlLick,'http://')&&!stristr($urlLick,'https://'))
      {
     $chooseDetails['urllink']=('http://'.$urlLick);
      }
     }
     if($chooseDetails['createUid']!=$uid)
     {
     D('Choose')->addBrowseRecord($serialno);
     }
     $this->assign('choose',$chooseDetails);
     $this->display();
     }
     public function clickChoose()
     {
     $serialno = I('post.serialno',null,'string');
     $linkUrl = I('post.linkUrl',null,'string');
     D('Choose')->addClickRecord($serialno,$linkUrl);
     $this->ajaxReturn(array('status'=>1,'msg'=>'操作成功!'));
     }
     public function chooseDetails()
     {
     $uid = get_uid();
     $serialno = I('get.serialno',null,'string');
     $schooId = I('get.schooId',10183,'int');
     $chooseDetails = D('Choose')->get_chooseInfo($serialno,$schooId);
     if($chooseDetails['is_img']==1)
     {          //获得原图
                $bi = M('Picture')->where(array('status' => 1))->getById($chooseDetails['attach_ids']);
                if (!is_bool(strpos($bi['path'], 'http://'))) {
                    $chooseDetails['sourceId_img_big'] = $bi['path'];
                } else {
                    $chooseDetails['sourceId_img_big'] = getRootUrl() . substr($bi['path'], 1);
                }
     }
     $urlLick = $chooseDetails['urllink'];
     if($urlLick!=null)
     {
      if(!stristr($urlLick,'http://')&&!stristr($urlLick,'https://'))
      {
     $chooseDetails['urllink']=('http://'.$urlLick);
      }
     }
     if($chooseDetails['createUid']!=$uid)
     {
     D('Choose')->addBrowseRecord($serialno);
     }
     $this->assign('choose',$chooseDetails);
     $this->display();
     }

    public function chooseHall()
    {
    $chooseHall = D('Choose')->get_allChoose();
    foreach($chooseHall as &$v)
    {
     if($v['is_img']==1)
     {          //获得原图
                $bi = M('Picture')->where(array('status' => 1))->getById($v['attach_ids']);
                if (!is_bool(strpos($bi['path'], 'http://'))) {
                    $v['sourceId_img_big'] = $bi['path'];
                } else {
                    $v['sourceId_img_big'] = getRootUrl() . substr($bi['path'], 1);
                }
     }
     $urlLick = $v['urllink'];
     if($urlLick!=null)
     {
      if(!stristr($urlLick,'http://')&&!stristr($urlLick,'https://'))
      {
     $v['urllink']=('http://'.$urlLick);
      }
     }
     $v['releaseTime']=date('m/j',$v['createTime']);
    }
    $this->assign('chooseHall',$chooseHall);
    $this->display();






    }




}



